<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>硅谷健康</title>
    <meta name="description" content="硅谷健康">
    <meta name="keywords" content="硅谷健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->

    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
        .el-calendar-table:not(.is-range) td.next, .el-calendar-table:not(.is-range) td.prev{
            pointer-events: none;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>预约列表</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="会员名/套餐名" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                    <el-select label="预约状态" v-model="pagination.queryStatus">
                        <el-option label="--请选择--" value="-1"></el-option>
                        <el-option label="已预约" value="0"></el-option>
                        <el-option label="预约成功" value="1"></el-option>
                        <el-option label="未到诊断" value="2"></el-option>
                    </el-select>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table v-loading="loading"  element-loading-text="拼命加载中" size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号码" align="center"></el-table-column>
                <el-table-column prop="sname" label="套餐名称" align="center"></el-table-column>

                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column label="预约状态" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.orderStatus == '0' ? '已预约' : scope.row.orderStatus == '1' ? '预约成功' : '未到诊断'}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">确认预约</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">取消预约</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增检查组" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="会员姓名">
                                                <el-select v-model="formData.memberId" placeholder="请选择">
                                                    <el-option v-for="item in members" :label="item.name" :value="item.id"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="预约类型">
                                                <el-input v-model="formData.orderType"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="预约状态">
                                                <el-select v-model="formData.orderStatus">
                                                    <el-option label="已预约" value="0"></el-option>
                                                    <el-option label="预约完成" value="1"></el-option>
                                                    <el-option label="未到诊断" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-form-item label="套餐名称">
                                        <el-select v-model="formData.setmealId" placeholder="请选择">
                                            <el-option v-for="item in setmeals" :label="item.name" :value="item.id"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-form>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data:{
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,//当前页码
                pageSize:5,//每页显示的记录数
                total:0,//总记录数
                queryString:null,//当前页要展示的分页列表数据
                queryStatus:null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData:[],//新增和编辑表单中对应的检查项列表数据
            members:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            setmeals:[],
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit:false//控制编辑窗口显示/隐藏
        },
        created() {
            this.findPage();
        },
        methods: {
            //添加
            handleAdd () {
                alert("formData:"+this.formData)
                //发送ajax请求
                axios.post("/order/add.do",this.formData)
                    .then((response=>{
                        //关闭新增窗口
                        this.dialogFormVisible=false;
                        if (response.data.flag){
                            //新增成功,弹出成功提示
                            this.$message({
                                message:response.data.message,
                                type:'success'
                            })
                        }else{
                            //新增失败
                            this.$message.error(response.data.message);
                        }
                    })).catch(response=>{
                    alert("error!");
                }).finally(()=>{
                        this.findPage();
                    }

                );
            },
            handleUpdate(row){
                console.log((row))
                if(row.orderStatus==0){
                    axios.get("/order/updateById.do?id="+row.id).then((res)=>{
                        if (res.data.flag){
                            //为模型数据设置值,基于VUE双向绑定回显到页面
                            this.$message.success("预约成功");
                            //调用分页
                            this.findPage();
                        }else{
                            this.$message.error("获取数据失败,请刷新当前页面");
                        }
                    });
                }else{
                    this.$message.error("当前状态不能确认预约哦！");
                }
            },
            handleDelete(row){
                console.log((row))
                if(row.orderStatus==2){
                    this.$message.error("当前状态已经取消预约过了哦！");
                }else{
                    axios.get("/order/updateById2.do?id="+row.id).then((res)=>{
                        if (res.data.flag){
                            //为模型数据设置值,基于VUE双向绑定回显到页面
                            this.$message.success("取消成功!");
                            //调用分页
                            this.findPage();
                        }else{
                            this.$message.error("取消预约失败!,请刷新当前页面");
                        }
                    });
                }
            },
            //分页查询
            findPage() {
                //分页参数
                var param={
                    currentPage:this.pagination.currentPage,//页码
                    pageSize:this.pagination.pageSize,//每页显示的记录数
                    queryString:this.pagination.queryString, //查询条件
                    queryStatus:this.pagination.queryStatus
                };
                //请求后台
                axios.post("/order/findPage.do",param).then((response)=>{
                    //为模型数据赋值,基于VUE的双向绑定展示到页面
                    this.dataList=response.data.rows;
                    this.pagination.total=response.data.total;
                }).catch(()=>{
                    alert("/order/findPage.do error!");
                });
            },
            // 重置表单
            resetForm() {
                this.formData={};
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible=true;
                //默认切换到第一个标签页(基本信息)
                this.activeName='first';
                //重置:
                this.members=[];
                //发送ajax请求查询所有检查项信息
                axios.get("/order/findAll.do").then((res=>{
                    if (res.data.flag){
                        //this.tableData=res.data.data;
                        //console.log(res.data.data)
                        this.members=res.data.data;
                    }else{
                        this.$message.error(res.data.message);
                    }
                }));
                axios.get("/order/findAll2.do").then((res=>{
                    if (res.data.flag){
                        this.tableData=res.data.data;
                        //console.log(res.data.data)
                        this.setmeals=res.data.data;
                    }else{
                        this.$message.error(res.data.message);
                    }
                }));

            },
            //切换页码
            handleCurrentChange(currentPage) {
                //currentPage为切换后的页码
                this.pagination.currentPage=currentPage;
                this.findPage();
            },
        }
    })
</script>
</html>
